{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "def uniquePathsWithObstacles(obstacleGrid: List[List[int]]) -> int:\n",
    "    # 初始化动态规划数组，\n",
    "    # 只能向下，向右走，故第一行，第一列置为1\n",
    "    m, n = len(obstacleGrid), len(obstacleGrid[0])\n",
    "    dp = [[1]*n] + [[1]+[0]*(n-1)for _ in range(m-1)]\n",
    "\n",
    "    for i in range(0, m):\n",
    "        if obstacleGrid[i][0] == 1:\n",
    "            while i < m:\n",
    "                dp[i][0] = 0\n",
    "                i += 1\n",
    "\n",
    "    for j in range(0, n):\n",
    "        if obstacleGrid[0][j] == 1:\n",
    "            while j < n:\n",
    "                dp[0][j] = 0\n",
    "                j += 1\n",
    "\n",
    "    for i in range(1, m):\n",
    "        for j in range(1, n):\n",
    "            if obstacleGrid[i][j] == 1:\n",
    "                dp[i][j] == 0\n",
    "            else:\n",
    "                # 动态转移数组，当前状态由左边的+上边的状态决定。\n",
    "                dp[i][j] = dp[i-1][j] + dp[i][j-1]\n",
    "            # for item in dp:\n",
    "            #     print(item)\n",
    "            # print()\n",
    "    return dp[-1][-1]"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
